package com.zhou.listener;

import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.liulishuo.filedownloader.FileDownloader;
import com.zhou.listener.bean.KeyGen;
import com.zhou.listener.library.ListenerManager;
import com.zhou.listener.baselistener.DetailFileDownloadListener;
import com.zhou.listener.listener.RecyclerDownloadListener;
import com.zhou.listener.library.utils.IKey;
import com.zhou.listener.library.vh.BaseDownloadViewHolder;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class EaseViewHolder extends BaseViewHolder<MyBean> implements BaseDownloadViewHolder {
    public Button name;
    String path;
    public List<IKey> keys;
    public EaseViewHolder(ViewGroup parent, int res) {
        super(parent, res);
        name = $(R.id.name);
        path = parent.getContext().getCacheDir().getPath()+File.separator + "image_manager_disk_cache";
    }

    @Override
    public void setData(final MyBean data) {
        super.setData(data);
        name.setText(data.name);
        name.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                FileDownloader.getImpl().create(data.url)
                        .setPath(path)
                        .setForceReDownload(true)
                        .setListener(ListenerManager.getInstance().addListener(getKeys().get(0),
                                new DetailFileDownloadListener(new RecyclerDownloadListener(EaseViewHolder.this))
                        )).start();
            }
        });
        keys = new ArrayList<>();
        keys.add(new KeyGen(data.id+""));
    }

    @Override
    public List<IKey> getKeys() {
        return keys;
    }

    @Override
    public void setKeys(List<IKey> keys) {
        this.keys = keys;
    }


}
